var role = requestData(path+"/role");
var department = requestData(path+"/department");
var rows;
$(function(){
   var data = {
		method: "GET",
		url:path+'/user',
		columns: [
			{field:'checked',checkbox:true},
			{field:'userId',title:'编号',visible:false},
			{field:'userName',title:'用户名'},
			{field:'useAuthor',title:'使用者'},
			{
				field:'userDepartment',
				title:'部门',
				formatter:function(value,row,index)
				{
					for(var item=0;item<department.length;item++){
						if(department[item].deptId==value){
							return department[item].deptName;
						}
					}
				}
			},
			{field:'userRole',title:'职位',formatter:function(value,row,index){for(var item=0;item<role.length;item++){if(role[item].roleId==value){return role[item].roleName;}}}},{field:'userLinkMethod',title:'联系方式'},{field:'userCreateTime',title:'创建时间'},{field:'userRemark',title:'备注'}
		 ],	
		 sortable: true,
         sortOrder: "asc",
         search: false,
   }
   
   //包装成key和value格式
   var roleMap = toKeyValueMap(role);
   var departmentMap = toKeyValueMap(department);
   
   var param = [{text:"部门",name:"userDepartment",type:"select",option:departmentMap},{text:"职位",name:"userRole",type:"select",option:roleMap},{text:"用户名",name:"userName",type:"text",verify:"cnw"},{text:"使用者",name:"useAuthor",type:"text",verify:"cnw"}];
   
   createQueryPanel(param);
   
   renderTable(cTable,data);
   
   form.render();
})

$("#add_btn").click(function(){
	
	openOperateWindow({
		title: "添加账号",
		url: "/admin/systemManagement/userManagement/user-add.jsp"
	})
})

$("#remove_btn").click(function(){
	requestRemoveData("userId","/user");
});

$("#modify_btn").click(function(){
	
	openOperateWindow({
		title: "添加账号",
		isUpdate: true,
		url: "/admin/systemManagement/userManagement/user-update.jsp"
	})
})
